/**
 *  时间字符串拼接
 * @param dateTimeString
 * @returns {*}
 */
import {inisHelper} from "@/utils/helper";

export function formatDateTime(dateTimeString) {
    // 创建一个Date对象
    const dateTime = new Date(dateTimeString);

    // 验证日期是否有效
    if (isNaN(dateTime.getTime())) {
       return Date.now()
    }

    // 使用Date对象的方法获取年、月、日、时、分
    const year = dateTime.getFullYear();
    const month = String(dateTime.getMonth() + 1).padStart(2, '0'); // getMonth返回的是0-11，所以需要+1
    const day = String(dateTime.getDate()).padStart(2, '0');
    const hours = String(dateTime.getHours()).padStart(2, '0');
    const minutes = String(dateTime.getMinutes()).padStart(2, '0');

    // 拼接字符串
    return `${year}-${month}-${day} ${hours}:${minutes}`;
}


const env = import.meta.env;
const baseUrl= env.VITE_APP_APT_BASEURL;
import avatarSvg from '@/assets/svg/avatar.svg';

export function formatUrlAvatar(url){
    if (url === undefined || url ===""){
       return avatarSvg ;
    }
    if (url.includes('http')||url.includes('https')){
        return url
    }else {
        return baseUrl+url
    }
}


export function formatUrl(url){
    if (inisHelper.is.empty(url)){
        return "" ;
    }
    if (url.includes('http')||url.includes('https')){
        return url
    }else {
        return baseUrl+url
    }
}
